﻿using System;
using HiTeachers.Services;

namespace HiTeachers.Web
{
    public partial class ListNews : PageBase
    {
        private const int NumNewInPage = 30;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;

            var curPage = string.IsNullOrEmpty(Request["p"]) ? 0 : Convert.ToInt32(Request["p"]) - 1;
            rptNews.DataSource = NewServices.GetNews(NumNewInPage, curPage);
            rptNews.DataBind();

            BindingPage();
        }

        #region Private Methods
        private void BindingPage()
        {
            var totalNew = NewServices.TotalNumberOfNew();
            var totalPage = (int)Math.Ceiling((double)totalNew / NumNewInPage);
            var curPage = string.IsNullOrEmpty(Request["p"]) ? 1 : Convert.ToInt32(Request["p"]);

            BindingPaper(ltrPaper, "ListNews.aspx", curPage, totalPage);
        }
        #endregion
    }
}
